/* 批量管理 */
import React, { PureComponent } from 'react'
import { Form, Select, Input, Cascader, Checkbox, Button, message } from 'antd';
import { operationQuestionBank } from '@/services/questionsBank'
import { isLianxi } from '@/utils/utils'
const layout = {
    labelCol: { span: 2 },
    wrapperCol: { span: 8 },
};
const tailLayout = {
    wrapperCol: { offset: 2, span: 16 },
};
export default class Index extends PureComponent<any, any> {
    constructor(props: any) {
        super(props)
        this.state = {
            types: '',
            type: '',
            subject: [],
            q_type: ''
        }
    }
    changeValue = (e: any, name: string) => {
        this.setState({
            [name]: e
        })
    }
    submitHandle = () => {
        const { types, type, subject, q_type } = this.state;
        if (!q_type) return message.error('请选择操作方式')
        if (!types[0]) return message.error('请选择题库')
        if (!subject[0]) return message.error('请选择科目')
        if (!type) return message.error('请选择题型')
        operationQuestionBank({ types: types.sort(), type, subject, q_type }).then(res => {
            if (res.status === 1) {
                message.success('操作成功')
            } else {
                message.error('操作失败')
            }
        })
    }
    render() {
        const { subjectOptions } = this.props;
        return (
            <div>
                <Form>
                    <Form.Item {...layout} label="操作方式">
                        <Select placeholder="请选择操作方式" onChange={(e) => this.changeValue(e, 'q_type')} >
                            <Select.Option key="1" value="1">批量禁用</Select.Option>
                            <Select.Option key="2" value="2">批量启用</Select.Option>
                            <Select.Option key="3" value="3">批量删除</Select.Option>
                        </Select>
                    </Form.Item>
                    <Form.Item {...layout} label="所属题库">
                        <Checkbox.Group style={{ width: '100%' }} onChange={(e) => this.changeValue(e, 'types')} >
                            <Checkbox key="3" value="3">模拟题库</Checkbox>
                            <Checkbox key="2" value="2">练习题库</Checkbox>
                            <Checkbox key="1" value="1">正式题库</Checkbox>
                            {/* <Checkbox key="4" value="4">每日一题</Checkbox> */}
                        </Checkbox.Group>
                    </Form.Item>
                    <Form.Item {...layout} label="所属科目">
                        <Cascader options={subjectOptions} onChange={(e) => this.changeValue(e, 'subject')} />
                    </Form.Item>
                    <Form.Item {...layout} label="所属题型">
                        <Select placeholder="请选择题型" onChange={(e) => this.changeValue(e, 'type')} >
                            <Select.Option key="1" value="1">单选题</Select.Option>
                            {
                                !isLianxi() && <Select.Option key="2" value="2">多选题</Select.Option>
                            }
                            <Select.Option key="3" value="3">判断题</Select.Option>
                        </Select>
                    </Form.Item>
                    <Form.Item {...tailLayout} >
                        <Button type="primary" onClick={this.submitHandle}>提交</Button>
                    </Form.Item>
                </Form>
            </div>
        )
    }
}
